/**
 * Copyright (C), 2020-2020, 软件公司
 * FileName: PriorityConsumer
 * Author:   cakin
 * Date:     2020/5/11
 * Description:
 */
package com.rabbitmq.priority;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import com.rabbitmq.client.AMQP;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.util.ConnectionUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: PriorityConsumer
 * @Description: TODO
 * @Date: 2020/5/11
 * @Author: cakin
 */
@Slf4j
public class PriorityConsumer {
    public static void main( String[] args ) {
        try {
            Connection connection = ConnectionUtils.getConnection();
            Channel channel = connection.createChannel();
            // 消费消息
            channel.basicConsume("queue_priority", true, new DefaultConsumer(channel) {
                @Override
                public void handleDelivery( String consumerTag, Envelope envelope,
                                            AMQP.BasicProperties properties, byte[] body ) throws IOException {
                    // 接收到的消息
                    String message = new String(body);
                    log.info(" [x] Received '" + message + "'");
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
    }
}
